/**
 * 工具类
 */
define(function (require, exports, module) {
    var $ = require("jquery");

    var Util = {
        /**
         * 获取url参数
         * @param {String} name 参数名
         * @param {String=} url
         * @returns {String} 参数值
         */
        getUrlPara: function (name, url) {
            url = url || window.location.href;
            var search = this.getUrlObj(url).search;
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = search.match(reg);
            if (r != null) {
                return decodeURIComponent(r[2]);
            }
            return "";
        },
        /**
         * 获取url各参数
         * @param {string?} url 相对或绝对地址
         * @returns {{host: string, hostname: string, hash: string, pathname: string, port: string, search: string}}
         */
        getUrlObj: function (url) {
            url = url || location.href;

            if (url.indexOf('http') === 0) {
                //nothing
            } else if (url.indexOf('//') === 0) {
                url = location.protocol + url;
            } else if (url.indexOf('/') === 0) {
                url = location.protocol + '//' + location.host + url;
            } else if (url.indexOf('/') !== 0) {
                //相对路径
                url = location.protocol + '//' + location.host + location.pathname.substring(0, location.pathname.lastIndexOf('/')) + '/' + url;
            }

            var l = document.createElement("a");
            l.href = url;

            var pathname = l.pathname;
            if (pathname.indexOf('/') !== 0) {
                pathname = '/' + pathname;
            }

            return {
                protocol: l.protocol,
                host: l.host,
                hostname: l.hostname,
                search: l.search.replace(/^\?/, ''),
                hash: l.hash.replace(/^#/, ''),
                pathname: pathname,
                port: l.port
            };
        },
        /**
         * 获取query对象
         * @param {string=} search
         * @returns {{}}
         */
        getQueryParams: function (search) {
            if (typeof search === 'undefined') {
                search = document.location.search;
            }
            var keyValueArr = search.replace(/(^\?)/, '').split("&");

            var res = {};
            var keyValue;
            for (var i = 0, temp; keyValue = keyValueArr[i]; i++) {
                temp = keyValue.split("=");
                res[temp[0]] = decodeURIComponent(temp[1]);
            }

            return res;
        },
        /**
         * 设置url参数
         * @param {string} key
         * @param {string} value
         * @param {string} url
         * @returns {string}
         */
        setUrlPara: function (key, value, url) {
            var urlObj = this.getUrlObj(url);
            var path = urlObj.pathname,
                search = urlObj.search,
                hash = urlObj.hash;

            key = encodeURI(key);
            value = encodeURI(value);

            var kvp = (search && search.split('&')) || [];

            var i = kvp.length;
            var x;
            while (i--) {
                x = kvp[i].split('=');

                if (x[0] == key) {
                    x[1] = value;
                    kvp[i] = x.join('=');
                    break;
                }
            }

            if (i < 0) {
                kvp[kvp.length] = [key, value].join('=');
            }
            search = kvp.join('&');

            url = urlObj.protocol + "//" + urlObj.host + path;
            if (search) {
                url += '?' + search;
            }
            if (hash) {
                url += '#' + hash;
            }

            return url;
        },
        /**
         * 格式化日期
         * @param {Date} dt 日期对象
         * @param {string} fmt 格式字符串，支持如下格式
         * 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符，
         * 年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
         * 例子：
         * yyyy-MM-dd hh:mm:ss.S ==> 2006-07-02 08:09:04.423
         * yyyy-M-d h:m:s.S ==> 2006-7-2 8:9:4.18
         * @returns {String}
         */
        formatDate: function (dt, fmt) {
            if (typeof dt == 'string') {
                dt = Util.parseDate(dt);
            }
            if (!dt || dt.constructor !== Date) {
                return "";
            }
            var o = {
                "M+": dt.getMonth() + 1, //月份
                "d+": dt.getDate(), //日
                "h+": dt.getHours(), //小时
                "m+": dt.getMinutes(), //分
                "s+": dt.getSeconds(), //秒
                "q+": Math.floor((dt.getMonth() + 3) / 3), //季度
                "S": dt.getMilliseconds()             //毫秒
            };
            if (/(y+)/.test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (dt.getFullYear() + "").substr(4 - RegExp.$1.length));
            }
            for (var k in o) {
                if (new RegExp("(" + k + ")").test(fmt)) {
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                }
            }
            return fmt;
        },

        /**
         * 修复日期
         * @param {Date} d 日期对象
         * @param {bool} check 是否检测
         */
        fixDate: function (d, check) {
            if (+d) {
                while (d.getDate() != check.getDate()) {
                    d.setTime(+d + (d < check ? 1 : -1) * HOUR_MS);
                }
            }
        },

        /**
         * 解析日期
         * @param {String} s 日期字符串
         * @param {bool} ignoreTimezone 是否忽略时区
         * @returns {Date}
         */
        parseDate: function (s, ignoreTimezone) {
            if (typeof s == 'object') {
                return isNaN(s) ? null : s;
            }
            if (typeof s == 'number') {

                var d = new Date(s * 1000);
                if (d.getTime() != s) return null;
                return isNaN(d) ? null : d;
            }
            if (typeof s == 'string') {

                m = s.match(/^([0-9]{4})([0-9]{2})([0-9]{2})$/);
                if (m) {
                    var date = new Date(m[1], m[2] - 1, m[3]);
                    return date;
                }


                m = s.match(/^([0-9]{4}).([0-9]*)$/);
                if (m) {
                    var date = new Date(m[1], m[2] - 1);
                    return date;
                }

                if (s.match(/^\d+(\.\d+)?$/)) {
                    var d = new Date(parseFloat(s) * 1000);
                    if (d.getTime() != s) return null;
                    else return d;
                }
                if (ignoreTimezone === undefined) {
                    ignoreTimezone = true;
                }
                var d = this.parseISO8601(s, ignoreTimezone) || (s ? new Date(s) : null);
                return isNaN(d) ? null : d;
            }

            return null;
        },

        /**
         * 解析日期
         * @param {String} s 日期字符串
         * @param {bool} ignoreTimezone 是否忽略时区
         * @returns {Date}
         */
        parseISO8601: function (s, ignoreTimezone) {
            var m = s.match(/^([0-9]{4})([-\/]([0-9]{1,2})([-\/]([0-9]{1,2})([T ]([0-9]{1,2}):([0-9]{1,2})(:([0-9]{1,2})(\.([0-9]+))?)?(Z|(([-+])([0-9]{2})(:?([0-9]{2}))?))?)?)?)?$/);
            if (!m) {
                m = s.match(/^([0-9]{4})[-\/]([0-9]{2})[-\/]([0-9]{2})[T ]([0-9]{1,2})/);
                if (m) {
                    var date = new Date(m[1], m[2] - 1, m[3], m[4]);
                    return date;
                }

                m = s.match(/^([0-9]{4}).([0-9]*)/);
                if (m) {
                    var date = new Date(m[1], m[2] - 1);
                    return date;
                }


                m = s.match(/^([0-9]{4}).([0-9]*).([0-9]*)/);
                if (m) {
                    var date = new Date(m[1], m[2] - 1, m[3]);
                    return date;
                }


                m = s.match(/^([0-9]{2})-([0-9]{2})-([0-9]{4})$/);
                if (!m) return null;
                else {
                    var date = new Date(m[3], m[1] - 1, m[2]);
                    return date;
                }
            }
            var date = new Date(m[1], 0, 1);
            if (ignoreTimezone || !m[14]) {
                var check = new Date(m[1], 0, 1, 9, 0);
                if (m[3]) {
                    date.setMonth(m[3] - 1);
                    check.setMonth(m[3] - 1);
                }
                if (m[5]) {
                    date.setDate(m[5]);
                    check.setDate(m[5]);
                }
                this.fixDate(date, check);
                if (m[7]) {
                    date.setHours(m[7]);
                }
                if (m[8]) {
                    date.setMinutes(m[8]);
                }
                if (m[10]) {
                    date.setSeconds(m[10]);
                }
                if (m[12]) {
                    date.setMilliseconds(Number("0." + m[12]) * 1000);
                }
                this.fixDate(date, check);
            } else {
                date.setUTCFullYear(
                    m[1],
                    m[3] ? m[3] - 1 : 0,
                    m[5] || 1
                );
                date.setUTCHours(
                    m[7] || 0,
                    m[8] || 0,
                    m[10] || 0,
                    m[12] ? Number("0." + m[12]) * 1000 : 0
                );
                var offset = Number(m[16]) * 60 + (m[18] ? Number(m[18]) : 0);
                offset *= m[15] == '-' ? 1 : -1;
                date = new Date(+date + (offset * 60 * 1000));
            }
            return date;
        },

        /**
         * 加载js文件
         * @param {string} url
         * @param {function} callback
         * @param {object} context
         * @returns {undefined}
         */
        loadJs: function (url, callback, context) {
            var node = document.createElement("script");
            node[window.addEventListener ? "onload" : "onreadystatechange"] = function () {
                if (window.addEventListener || /loaded|complete/i.test(node.readyState)) {
                    callback.call(context);
                    node.onreadystatechange = null;
                }
            }
            node.onerror = function () {
            };
            node.src = url;
            var head = document.getElementsByTagName("head")[0];
            head.insertBefore(node, head.firstChild);     //插入到head的第一个节点前，防止ie6下head标签没闭合前，使用appendChild报错。　
        },
        /**
         * 格式化数字
         * @param {number} number 为要格式化的数字
         * @param {int} decimals 为小数位位数，如果不传则没有小数位
         * @param {string} dec_point 为小数位分隔符，默认为.
         * @param {string} thousands_sep 为千分位分隔符，默认为,
         * @returns {string}
         */
        formatNumber: function (number, decimals, dec_point, thousands_sep) {
            number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
            var n = !isFinite(+number) ? 0 : +number,
                prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
                sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
                dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
                s = '',
                toFixedFix = function (n, prec) {
                    var k = Math.pow(10, prec);
                    return '' + (Math.round(n * k) / k).toFixed(prec);
                };
            // Fix for IE parseFloat(0.55).toFixed(0) = 0;
            s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
            if (s[0].length > 3) {
                s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
            }
            if ((s[1] || '').length < prec) {
                s[1] = s[1] || '';
                s[1] += new Array(prec - s[1].length + 1).join('0');
            }
            return s.join(dec);
        },
        /**
         * 获取cookie
         * @param {string} name
         * @returns {String}
         */
        getCookie: function (name) {
            var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
            if (arr != null) {
                return unescape(arr[2]);
            }
            return "";
        },
        /**
         * 设置cookie的值
         * @param {string} name 名称
         * @param {string} value 值
         * @param {int} expires 过期天数
         * @param {type} path
         * @param {type} domain
         * @param {type} secure
         * @returns {undefined}
         */
        setCookie: function (name, value, expires, path, domain, secure) {
            domain = domain || G_CONFIG["domain"]; //域名
            var today = new Date();
            if (expires) {
                expires = expires * 24 * 3600 * 1000; //转为毫秒
            }
            var expires_date = new Date(today.getTime() + expires);
            document.cookie = name + '=' + escape(value)
                + (expires ? ';expires=' + expires_date.toGMTString() : '')
                + (path ? ';path=' + path : '')
                + (domain ? ';domain=' + domain : '')
                + (secure ? ';secure' : '');
        },
        /**
         * 删除cookie
         * @param {string} name 名称
         * @returns {undefined}
         */
        delCookie: function (name) {
            if (this.getCookie(name)) {
                document.cookie = name + "=" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
            }
        },
        /**
         * 跳转登录页面，默认登陆后重定向回当前页面
         * @param {string?} url
         */
        goToLoginPage: function (url) {
            url = (typeof(url) === 'undefined' || url === null) ? location.href : url;

            if (url === '') {
                location.href = "/login.shtml";
            } else {
                location.href = "/login.shtml?ret_url=" + encodeURIComponent(url);
            }
        },
        /**
         * 封装jQuery ajax方法
         * @param {Object} options
         * @returns {undefined}
         */
        myAjax: function (options) {
            var data = options["data"] || {};
            var async = typeof(options["async"]) == 'undefined' ? true : options["async"];

            var needToken = data['NEED_TOKEN'] !== false;
            delete data['NEED_TOKEN'];

            if (needToken) {
                var token = data["token"] || this.getToken();
                if (token) {
                    data["token"] = token;
                }
            }

            var self = this;
            return $.ajax({
                url: options["url"],
                type: options["type"],
                context: this,
                cache: false,
                async: async,
                data: data,
                success: function (json) {
                    if (typeof json === "string") {
                        json = $.parseJSON(json);
                    }
                    var retCode = json.retCode;
                    if (retCode == "-1168002") {//未登录
                        self.goToLoginPage();
                    } else if (retCode === '-1168201' || retCode === '-1168202' || retCode === '-1168203') {//权限
                        Util.showNoPagePermission(json.errMsg);
                        //} else if (retCode.indexOf('-116') === 0) {//系统错误
                        //    self.alert(json['errMsg'] || "系统错误，请稍后再试");
                    } else if (retCode === '-1190151') {
                        Util.showNoFunctionPermission(json['errMsg']);
                    } else if (typeof options["success"] == "function") {
                        options["success"].call(options["context"], json);
                    }
                },
                error: function (xhr, txtStatus) {
                    if (options["error"]) {
                        options["error"].call(options["context"], xhr, txtStatus);
                    } else {
                        self.alert("服务器系统内部错误，请稍后再试！");
                    }
                },
                complete: function (xhr, txtStatus) {
                    if (typeof options['complete'] == "function") {
                        options['complete'].call(options['context'], xhr, txtStatus);
                    }
                }
            });
        },
        /**
         * 展示无页面访问权限提示
         */
        showNoPagePermission: function (errMsg) {
            Util.showDialog({
                id: "__permission_alert__",
                title: '提示',
                fixed: true,
                content: errMsg || '对不起，您没有权限访问该页面',
                width: 350,
                okValue: '返回首页',
                cancelDisplay: false,
                ok: function () {
                    location.href = '/';
                    return true;
                },
                cancel: function () {
                    location.href = '/';
                    return true;
                }
            });
        },
        /**
         * 展示无功能访问权限提示
         */
        showNoFunctionPermission: function (message) {
            Util.showDialog({
                id: "__permission_alert__",
                title: '提示',
                fixed: true,
                content: message || '对不起，您没有权限访问该功能',
                width: 350,
                okValue: '确定',
                cancelDisplay: false,
                ok: function () {
                    //location.href = '/';
                    return true;
                },
                cancel: function () {
                    return true;
                }
            });
        },
        /**
         * 显示弹层
         * @param config
         */
        showDialog: function (config) {
            require.async("dialog", function (dialog) {
                dialog(config).showModal();
            });
        },
        /**
         * alert提示框
         * @param {string} msg
         * @param {{ok:function=}=} cfg
         */
        alert: function (msg, cfg) {
            var title = (cfg && cfg["title"]) || "提示",
                width = (cfg && cfg["width"]) || 350,
                okValue = (cfg && cfg["okValue"]) || "确定";
            return Util.showDialog({
                id: "__alert_dialog__",
                title: title,
                fixed: true,
                content: msg,
                width: width,
                okValue: okValue,
                cancelDisplay: false,
                ok: function () {
                    if (cfg && typeof cfg.ok == "function") {
                        return cfg.ok();
                    }
                    return true;
                },
                cancel: function () {
                    if (cfg && typeof cfg.cancel == "function") {
                        return cfg.cancel();
                    }
                }
            });
        },
        /**
         * alert提示框，N 秒后自动关闭
         * @param {string} msg
         * @param {string} delay
         */
        notify: function (msg, delay) {
            delay = delay || 2000; // 自动关闭默认值
            var title = "提示",
                width = 350,
                okValue = "确定";
            var cfg = {
                id: "__notify_dialog__",
                title: title,
                fixed: true,
                content: msg,
                width: width,
                okValue: okValue,
                cancelDisplay: false,
                ok: function () {
                    return true;
                }
            };

            require.async("dialog", function (dialog) {
                var d = dialog(cfg).showModal();
                setTimeout(function () {
                    d.remove();
                }, delay);
            });
        },
        /**
         * confirm提示框
         * @param {string} msg
         * @param {{ok:function=,cancel:function=}=} cfg
         */
        confirm: function (msg, cfg) {
            var title = (cfg && cfg["title"]) || "提示",
                width = (cfg && cfg["width"]) || 350,
                okValue = (cfg && cfg["okValue"]) || "确定",
                cancelValue = (cfg && cfg["cancelValue"]) || "取消";
            Util.showDialog({
                id: "__confirm_dialog__",
                title: title,
                fixed: true,
                content: msg,
                width: width,
                okValue: okValue,
                cancelValue: cancelValue,
                cancelDisplay: true,
                ok: function () {
                    if (cfg && typeof cfg.ok == "function") {
                        return cfg.ok();
                    }
                    return true;
                },
                cancel: function () {
                    if (cfg && typeof cfg.cancel == "function") {
                        return cfg.cancel();
                    }
                    return true;
                }
            });
        },
        //返回浏览器顶部
        goToTop: function (e) {
            var event = e || window.event;
            event.preventDefault();
            var winTop = $(window).scrollTop();
            $('body').animate({scrollTop: 0}, winTop / 4);
        },
        /**
         * 转义html字符串
         * @param {string} html
         * @returns {string}
         */
        escapeHtml: function (html) {
            return html.replace(/</g, '&lt;').replace(/>/g, '&gt;');
        },
        /**
         * 获取token参数
         * @returns {string}
         */
        getToken: function () {
            var token = this.getUrlPara("token");
            if (!token) {
                token = this.getCookie("token");
            }
            return token || "";
        },
        /**
         * 解析.net上传控件的数据，返回文件的url地址
         * @param {type} str
         * @returns {String}
         */
        parseImgUrl: function (str) {
            if (!str) {
                return "";
            }
            var obj = $.parseJSON(str);
            if (obj) {
                return obj[0].url || "";
            }
            return "";
        },
        /**
         * 判断元素在数组中位置
         * @param {Object} targetItem
         * @param {Array} arr
         * @param {function(Object,Object):boolean=} equalFunc 判断是否相等函数
         * @returns {int}
         */
        indexOf: function (targetItem, arr, equalFunc) {
            if (typeof equalFunc == 'function') {
                var item;
                for (var i = 0; item = arr[i]; i++) {
                    if (equalFunc(targetItem, item)) {
                        return i;
                    }
                }
                return -1;
            } else {
                if (Array.prototype.indexOf) {
                    return arr.indexOf(targetItem);
                } else {
                    var item;
                    for (var i = 0; item = arr[i]; i++) {
                        if (item === targetItem) {
                            return i;
                        }
                    }
                    return -1;
                }
            }
        },
        /**
         * 判断元素是否在数组中
         * @param {Object} targetItem
         * @param {Array} arr
         * @param {function(Object,Object):boolean=} equalFunc 判断是否相等函数
         * @returns {boolean}
         */
        inArray: function (targetItem, arr, equalFunc) {
            return this.indexOf(targetItem, arr, equalFunc) > -1;
        },
        /**
         * 从数组中移除元素
         * @param {Object} targetItem
         * @param {Array} arr
         * @param {function(Object,Object):boolean=} equalFunc 判断是否相等函数
         * @returns {boolean} 是否移除成功
         */
        removeFromArr: function (targetItem, arr, equalFunc) {
            var index = this.indexOf(targetItem, arr, equalFunc);
            if (index > -1) {
                arr.splice(index, 1);
                return true;
            }
            return false;
        },
        /**
         * 去重数组
         * @param {Array} arr
         * @param {function(Object,Object):boolean=} equalFunc
         * @returns {Array}
         */
        uniqueArr: function (arr, equalFunc) {
            var res = [];

            var item;
            for (var i = 0; item = arr[i]; i++) {
                if (!this.inArray(item, res, equalFunc)) {
                    res.push(item);
                }
            }

            return res;
        },
        /**
         * 获取key数组
         * @param {Object} obj
         * @returns {Array.<string>}
         */
        getKeys: function (obj) {
            var keys = [];

            if (obj) {
                for (var key in obj) {
                    if (obj.hasOwnProperty(key)) {
                        keys.push(key);
                    }
                }
            }

            return keys;
        },
        /**
         * 数字转换成字符串
         * @param {Number} n
         * @param {int} width
         * @param {string=} z
         * @returns {string}
         */
        pad: function (n, width, z) {
            z = z || '0';
            n = n + '';
            return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
        },
        /**
         * 检测当前浏览器信息
         * @returns {{}}
         */
        browser: function () {
            var browser = {};
            var ua = navigator.userAgent.toLowerCase();
            var s;
            (s = ua.match(/rv:([\d.]+)\) like gecko/)) ? browser.ie = s[1] :
                (s = ua.match(/msie ([\d.]+)/)) ? browser.ie = s[1] :
                    (s = ua.match(/firefox\/([\d.]+)/)) ? browser.firefox = s[1] :
                        (s = ua.match(/chrome\/([\d.]+)/)) ? browser.chrome = s[1] :
                            (s = ua.match(/opera.([\d.]+)/)) ? browser.opera = s[1] :
                                (s = ua.match(/version\/([\d.]+).*safari/)) ? browser.safari = s[1] : 0;
            return browser;
        },
        /**
         * 清除选中的区域
         */
        clearSelection: function () {
            try {
                if (this.browser().ie) {
                    document.selection.clear();
                } else {
                    window.getSelection().removeAllRanges();
                }
            } catch (e) {
            }
        },
        /**
         * 通过 POST 的方式下载文件，解决 GET 参数过长问题，比如统计报表项目列表参数过长
         * @param {String} url
         * @param {Object} data
         */
        download: function (url, data) {
            var idx = url.indexOf('?');
            var token = this.getToken();
            if (token) {
                if (idx < 0) {
                    url += '?token=' + token;
                } else {
                    var queryString = url.substr(idx + 1);
                    if (queryString.indexOf('token=') < 0) {
                        url += '&token=' + token;
                    }
                }
            }

            var id = 'temp-form-2AD1D283-0815-429B-99DD-087C9C7B6302';
            var tempForm = document.getElementById(id);
            if (!tempForm) {
                tempForm = document.createElement("form");
                tempForm.method = "post";
                tempForm.name = tempForm.id = id;
            }
            tempForm.action = url;
            if (document.body.firstChild) {
                // 防止低版本 IE 可能引起的兼容性问题
                document.body.insertBefore(tempForm, document.body.firstChild);
            }
            else {
                document.body.appendChild(tempForm);
            }

            tempForm.innerHTML = '';
            for (var key in data) {
                if (data.hasOwnProperty(key)) {
                    var val = data[key];
                    if ($.isPlainObject(val) || $.isArray(val)) {
                        // 自动把数据对象和数组序列化
                        val = JSON.stringify(val);
                    }
                    var field = document.createElement("input");
                    field.type = 'hidden';
                    field.name = key;
                    field.value = val;
                    if (tempForm.firstChild) {
                        tempForm.insertBefore(field, tempForm.firstChild);
                    } else {
                        tempForm.appendChild(field);
                    }
                }
            }
            tempForm.submit();
        },
        /**
         * 检测文件格式是否为图片
         * @param fileObj
         * @returns {boolean}
         */
        checkIsImagFile: function (fileObj) {
            if (!fileObj) {
                return true;
            }
            if (fileObj.type) {
                var fileType = fileObj.type || "";
                return /image\/(jpg|jpeg|png|gif)/i.test(fileType);
            } else if (fileObj.name) {
                //ie 9 取不到type属性，但可以取到name属性，判断文件扩展名。
                var fileName = fileObj.name;
                var ext = fileName.substring(fileName.lastIndexOf(".")).toLowerCase();
                return $.inArray(ext, [".jpg", ".jpeg", ".png", ".gif"]) != -1;
            }
            return true;
        },
        /**
         * 嵌套iframe
         * @param {string} selector
         * @param {string} iframeUrl
         * @param {int=} minHeight
         */
        nestIframe: function (selector, iframeUrl, minHeight) {
            var $pageIframeWrapper = $(selector);
            $pageIframeWrapper.parent().css({'background': 'url(/static_public/images/loading.gif) 59.5% 50% no-repeat'});

            function getIframeHeight() {
                var height = $(window).height();
                var documentHeight = $(document).height();
                if (documentHeight > height) {
                    height = documentHeight;
                }
                height = height - $('body>.top').outerHeight() - $('body>.footer').outerHeight() - 55;

                if (minHeight) {
                    height = Math.max(height, minHeight);
                }

                return height;
            }

            var url = iframeUrl || this.getUrlPara('iframe_url');
            var $ifram = $('<iframe frameborder="0" style="width:100%;"></iframe>');
            if (url) {
                $ifram
                    .attr('src', url)
                    .load(function () {
                        $pageIframeWrapper.parent().css({'background': 'none'});
                        $pageIframeWrapper.show();
                    })
                    .height(getIframeHeight())
                    .appendTo($pageIframeWrapper);
            }
            $(document).on('resize', function () {
                $ifram.height(getIframeHeight());
            });
            $(window).resize(function () {
                $ifram.height(getIframeHeight());
            });
        },
        /**
         * 计算删除行数据后，显示第几页
         * @param total 总条数
         * @param pageIndex 第几页
         * @param pageSize 每页条数
         * @param delCount 删除的条数
         * @returns {*|number}
         */
        calDeletedPage: function (total, pageIndex, pageSize, delCount) {
            var page = pageIndex || 1;
            if (page > 1) {
                var count = total - ((page - 1) * pageSize);
                if (count <= delCount) {
                    page--;
                }
            }
            return page;
        }
    };

    return Util;
});